﻿Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Globalization
Imports System.IO
Imports System.Reflection
Imports System.Workflow.ComponentModel.Compiler
Imports System.Workflow.ComponentModel.Design
Imports System.Workflow.ComponentModel.Serialization
Imports System.Xml

Namespace System.Workflow.ComponentModel
    Public NotInheritable Class WorkflowChanges
        ' Methods
        Public Sub New(ByVal rootActivity As Activity)
            If (rootActivity Is Nothing) Then
                Throw New ArgumentNullException("rootActivity")
            End If
            If (Not TypeOf rootActivity Is CompositeActivity OrElse (Not rootActivity.Parent Is Nothing)) Then
                Throw New ArgumentException(SR.GetString("Error_RootActivityTypeInvalid2"), "rootActivity")
            End If
            If rootActivity.DesignMode Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Me.originalRootActivity = DirectCast(rootActivity.GetValue(Activity.WorkflowDefinitionProperty), Activity)
            If (Me.originalRootActivity Is Nothing) Then
                Me.originalRootActivity = rootActivity
            End If
            Me.clonedRootActivity = WorkflowChanges.CloneRootActivity(Me.originalRootActivity)
            Me.ApplyDynamicUpdateMode(Me.clonedRootActivity)
        End Sub

        Private Sub ApplyDynamicUpdateMode(ByVal seedActivity As Activity)
            Dim queue As New Queue([Of] Activity)
            queue.Enqueue(seedActivity)
            Do While (queue.Count > 0)
                Dim activity As Activity = queue.Dequeue
                activity.Readonly = True
                activity.DynamicUpdateMode = True
                Dim property As DependencyProperty
                For Each property In activity.MetaDependencyProperties
                    If activity.IsBindingSet([property]) Then
                        Dim binding As ActivityBind = activity.GetBinding([property])
                        If (Not binding Is Nothing) Then
                            binding.DynamicUpdateMode = True
                        End If
                    End If
                Next
                If TypeOf activity Is CompositeActivity Then
                    Dim activity2 As CompositeActivity = [TryCast](activity,CompositeActivity)
                    AddHandler activity2.Activities.ListChanged, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanged)
                    Dim activity3 As Activity
                    For Each activity3 In DirectCast(activity, CompositeActivity).Activities
                        queue.Enqueue(activity3)
                    Next
                End If
            Loop
        End Sub

        Friend Sub ApplyTo(ByVal activity As Activity)
            If (activity Is Nothing) Then
                Throw New ArgumentNullException("activity")
            End If
            If (Not activity.Parent Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_RootActivityTypeInvalid"), "activity")
            End If
            If (activity.RootActivity Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_MissingRootActivity"))
            End If
            If (activity.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            If Me.saved Then
                Throw New InvalidOperationException(SR.GetString("Error_TransactionAlreadyApplied"))
            End If
            If Not WorkflowChanges.CompareWorkflowDefinition(Me.originalRootActivity, DirectCast(activity.RootActivity.GetValue(Activity.WorkflowDefinitionProperty), Activity)) Then
                Throw New ArgumentException(SR.GetString("Error_WorkflowDefinitionModified"), "activity")
            End If
            Me.Save
            Dim workflowCoreRuntime As IWorkflowCoreRuntime = activity.WorkflowCoreRuntime
            If (Not workflowCoreRuntime.CurrentAtomicActivity Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_InsideAtomicScope"))
            End If
            Dim flag As Boolean = workflowCoreRuntime.SuspendInstance(SR.GetString("SuspendReason_WorkflowChange"))
            Try 
                Dim list As New List([Of] Activity)
                Dim queue As New Queue([Of] Activity)
                queue.Enqueue(workflowCoreRuntime.RootActivity)
                Do While (queue.Count > 0)
                    Dim item As Activity = queue.Dequeue
                    list.Add(item)
                    Dim list2 As IList([Of] Activity) = DirectCast(item.GetValue(Activity.ActiveExecutionContextsProperty), IList([Of] Activity))
                    If (Not list2 Is Nothing) Then
                        Dim activity3 As Activity
                        For Each activity3 In list2
                            queue.Enqueue(activity3)
                        Next
                    End If
                Loop
                Dim errors As New ValidationErrorCollection
                Dim action As WorkflowChangeAction
                For Each action In Me.modelChangeActions
                    If TypeOf action Is ActivityChangeAction Then
                        Dim activity4 As Activity
                        For Each activity4 In list
                            If (TypeOf action Is RemovedActivityAction AndAlso (activity4.DottedPath = DirectCast(action, RemovedActivityAction).OriginalRemovedActivity.DottedPath)) Then
                                errors.AddRange(action.ValidateChanges(activity4))
                            End If
                            If (Not activity4.TraverseDottedPathFromRoot(DirectCast(action, ActivityChangeAction).OwnerActivityDottedPath) Is Nothing) Then
                                errors.AddRange(action.ValidateChanges(activity4))
                            End If
                        Next
                        [Continue] For
                    End If
                Next
                If errors.HasErrors Then
                    Throw New WorkflowValidationFailedException(SR.GetString("Error_RuntimeValidationFailed"), errors)
                End If
                Me.VerifyWorkflowCanBeChanged(workflowCoreRuntime)
                workflowCoreRuntime.OnBeforeDynamicChange(Me.modelChangeActions)
                workflowCoreRuntime.RootActivity.SetValue(Activity.WorkflowDefinitionProperty, Me.clonedRootActivity)
                Dim activity5 As Activity
                For Each activity5 In list
                    Dim action2 As WorkflowChangeAction
                    For Each action2 In Me.modelChangeActions
                        If (TypeOf action2 Is ActivityChangeAction AndAlso (Not activity5.TraverseDottedPathFromRoot(DirectCast(action2, ActivityChangeAction).OwnerActivityDottedPath) Is Nothing)) Then
                            action2.ApplyTo(activity5)
                        End If
                    Next
                    Dim activityByName As Activity = Me.clonedRootActivity.GetActivityByName(activity5.QualifiedName)
                    If (Not activityByName Is Nothing) Then
                        activity5.FixUpMetaProperties(activityByName)
                    End If
                    Me.NotifyChangesToChildExecutors(workflowCoreRuntime, activity5, Me.modelChangeActions)
                    Me.NotifyChangesCompletedToChildExecutors(workflowCoreRuntime, activity5)
                Next
                workflowCoreRuntime.OnAfterDynamicChange(True, Me.modelChangeActions)
            Catch obj1 As Object
                workflowCoreRuntime.OnAfterDynamicChange(False, Me.modelChangeActions)
                Throw
            Finally
                If flag Then
                    workflowCoreRuntime.Resume
                End If
            End Try
        End Sub

        Private Shared Function CloneRootActivity(ByVal originalRootActivity As Activity) As Activity
            Dim str As String = [TryCast](originalRootActivity.GetValue(Activity.WorkflowXamlMarkupProperty),String)
            Dim rulesMarkup As String = Nothing
            Dim rootActivity As Activity = Nothing
            Dim serviceProvider As IServiceProvider = [TryCast](originalRootActivity.GetValue(Activity.WorkflowRuntimeProperty),IServiceProvider)
            If Not String.IsNullOrEmpty(str) Then
                rulesMarkup = [TryCast](originalRootActivity.GetValue(Activity.WorkflowRulesMarkupProperty),String)
                rootActivity = Activity.OnResolveActivityDefinition(Nothing, str, rulesMarkup, True, False, serviceProvider)
            Else
                rootActivity = Activity.OnResolveActivityDefinition(originalRootActivity.GetType, Nothing, Nothing, True, False, serviceProvider)
            End If
            If (rootActivity Is Nothing) Then
                Throw New NullReferenceException(SR.GetString("Error_InvalidRootForWorkflowChanges"))
            End If
            Dim workflowChanges As ArrayList = DirectCast(originalRootActivity.GetValue(WorkflowChanges.WorkflowChangeActionsProperty), ArrayList)
            If (Not workflowChanges Is Nothing) Then
                workflowChanges = WorkflowChanges.CloneWorkflowChangeActions(workflowChanges, originalRootActivity)
                If (workflowChanges Is Nothing) Then
                    Return rootActivity
                End If
                Dim action As WorkflowChangeAction
                For Each action In workflowChanges
                    action.ApplyTo(rootActivity)
                Next
                rootActivity.SetValue(WorkflowChanges.WorkflowChangeActionsProperty, workflowChanges)
            End If
            Return rootActivity
        End Function

        Private Shared Function CloneWorkflowChangeActions(ByVal workflowChanges As ArrayList, ByVal rootActivity As Activity) As ArrayList
            If (workflowChanges Is Nothing) Then
                Throw New ArgumentNullException("workflowChanges")
            End If
            If (rootActivity Is Nothing) Then
                Throw New ArgumentNullException("rootActivity")
            End If
            Dim s As String = Nothing
            Dim serviceInstance As TypeProvider = WorkflowChanges.CreateTypeProvider(rootActivity)
            Dim provider As New ServiceContainer
            provider.AddService(GetType(ITypeProvider), serviceInstance)
            Dim manager As New DesignerSerializationManager(provider)
            Dim serializer As New WorkflowMarkupSerializer
            [Using] manager.CreateSession
                [Using] writer As StringWriter = New StringWriter(CultureInfo.InvariantCulture)
                    [Using] writer2 As XmlWriter = Helpers.CreateXmlWriter(writer)
                        Dim serializationManager As New WorkflowMarkupSerializationManager(manager)
                        serializer.Serialize(serializationManager, writer2, workflowChanges)
                        s = writer.ToString
                    End [Using]
                End [Using]
                [Using] reader As StringReader = New StringReader(s)
                    [Using] reader2 As XmlReader = XmlReader.Create(reader)
                        Dim manager3 As New WorkflowMarkupSerializationManager(manager)
                        Return [TryCast](serializer.Deserialize(manager3, reader2),ArrayList)
                    End [Using]
                End [Using]
            End [Using]
        End Function

        Private Shared Function CompareWorkflowDefinition(ByVal originalWorkflowDefinition As Activity, ByVal currentWorkflowDefinition As Activity) As Boolean
            If (originalWorkflowDefinition Is currentWorkflowDefinition) Then
                Return True
            End If
            If (Not originalWorkflowDefinition.GetType Is currentWorkflowDefinition.GetType) Then
                Return False
            End If
            Dim guid As Guid = DirectCast(originalWorkflowDefinition.GetValue(WorkflowChanges.WorkflowChangeVersionProperty), Guid)
            Dim guid2 As Guid = DirectCast(currentWorkflowDefinition.GetValue(WorkflowChanges.WorkflowChangeVersionProperty), Guid)
            Return (guid = guid2)
        End Function

        Friend Shared Function CreateTypeProvider(ByVal rootActivity As Activity) As TypeProvider
            Dim provider As New TypeProvider(Nothing)
            Dim type As Type = rootActivity.GetType
            provider.SetLocalAssembly(type.Assembly)
            provider.AddAssembly(type.Assembly)
            Dim name As AssemblyName
            For Each name In type.Assembly.GetReferencedAssemblies
                Dim assembly As Assembly = Nothing
                Try 
                    [assembly] = Assembly.Load(name)
                    If (Not [assembly] Is Nothing) Then
                        provider.AddAssembly([assembly])
                    End If
                Catch obj1 As Object
                End Try
                If (([assembly] Is Nothing) AndAlso (Not name.CodeBase Is Nothing)) Then
                    provider.AddAssemblyReference(name.CodeBase)
                End If
            Next
            Return provider
        End Function

        Private Shared Function DiffTrees(ByVal originalCompositeActivity As CompositeActivity, ByVal clonedCompositeActivity As CompositeActivity) As List([Of] WorkflowChangeAction)
            Dim list As New List([Of] WorkflowChangeAction)
            Dim enumerator As IEnumerator([Of] Activity) = clonedCompositeActivity.Activities.GetEnumerator
            Dim enumerator2 As IEnumerator([Of] Activity) = originalCompositeActivity.Activities.GetEnumerator
            Dim removedActivityIndex As Integer = 0
            Do While enumerator2.MoveNext
                Dim flag As Boolean = False
                Dim current As Activity = enumerator2.Current
                Do While enumerator.MoveNext
                    Dim activityAdded As Activity = enumerator.Current
                    If activityAdded.Readonly Then
                        If (current.DottedPath = activityAdded.CachedDottedPath) Then
                            removedActivityIndex += 1
                            flag = True
                            If TypeOf current Is CompositeActivity Then
                                list.AddRange(WorkflowChanges.DiffTrees([TryCast](current,CompositeActivity), [TryCast](activityAdded,CompositeActivity)))
                            End If
                        Else
                            list.Add(New RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity))
                            Do While enumerator2.MoveNext
                                current = enumerator2.Current
                                If (current.DottedPath = activityAdded.CachedDottedPath) Then
                                    removedActivityIndex += 1
                                    flag = True
                                    If TypeOf current Is CompositeActivity Then
                                        list.AddRange(WorkflowChanges.DiffTrees([TryCast](current,CompositeActivity), [TryCast](activityAdded,CompositeActivity)))
                                    End If
                                    Exit Do
                                End If
                                list.Add(New RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity))
                            Loop
                        End If
                        Exit Do
                    End If
                    list.Add(New AddedActivityAction(clonedCompositeActivity, activityAdded))
                    removedActivityIndex += 1
                Loop
                If Not flag Then
                    list.Add(New RemovedActivityAction(removedActivityIndex, current, clonedCompositeActivity))
                End If
            Loop
            Do While enumerator.MoveNext
                list.Add(New AddedActivityAction(clonedCompositeActivity, enumerator.Current))
            Loop
            Return list
        End Function

        Public Shared Function GetCondition(ByVal dependencyObject As Object) As Object
            If (dependencyObject Is Nothing) Then
                Throw New ArgumentNullException("dependencyObject")
            End If
            If Not TypeOf dependencyObject Is DependencyObject Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(DependencyObject).FullName }), "dependencyObject")
            End If
            Return [TryCast](dependencyObject,DependencyObject).GetValue(WorkflowChanges.ConditionProperty)
        End Function

        Friend Shared Function IsActivityExecutable(ByVal activity As Activity) As Boolean
            If Not activity.Enabled Then
                Return False
            End If
            If (Not activity.Parent Is Nothing) Then
                Return WorkflowChanges.IsActivityExecutable(activity.Parent)
            End If
            Return activity.Enabled
        End Function

        Private Sub NotifyChangesCompletedToChildExecutors(ByVal workflowCoreRuntime As IWorkflowCoreRuntime, ByVal contextActivity As Activity)
            Dim queue As New Queue
            queue.Enqueue(contextActivity)
            Do While (queue.Count > 0)
                Dim activity As CompositeActivity = [TryCast](queue.Dequeue,CompositeActivity)
                If ((Not activity Is Nothing) AndAlso WorkflowChanges.IsActivityExecutable(activity)) Then
                    Dim activityExecutor As ISupportWorkflowChanges = [TryCast](ActivityExecutors.GetActivityExecutor(activity),ISupportWorkflowChanges)
                    If (Not activityExecutor Is Nothing) Then
                        [Using] workflowCoreRuntime.SetCurrentActivity(activity)
                            [Using] context As ActivityExecutionContext = New ActivityExecutionContext(activity)
                                activityExecutor.OnWorkflowChangesCompleted(context)
                            End [Using]
                        End [Using]
                    End If
                    Dim activity2 As Activity
                    For Each activity2 In activity.Activities
                        If TypeOf activity2 Is CompositeActivity Then
                            queue.Enqueue(activity2)
                        End If
                    Next
                End If
            Loop
        End Sub

        Private Sub NotifyChangesToChildExecutors(ByVal workflowCoreRuntime As IWorkflowCoreRuntime, ByVal contextActivity As Activity, ByVal changeActions As IList([Of] WorkflowChangeAction))
            Dim action As WorkflowChangeAction
            For Each action In changeActions
                If TypeOf action Is ActivityChangeAction Then
                    Dim activity As CompositeActivity = [TryCast](contextActivity.TraverseDottedPathFromRoot(DirectCast(action, ActivityChangeAction).OwnerActivityDottedPath),CompositeActivity)
                    If ((Not activity Is Nothing) AndAlso WorkflowChanges.IsActivityExecutable(activity)) Then
                        Dim activityExecutor As ISupportWorkflowChanges = [TryCast](ActivityExecutors.GetActivityExecutor(activity),ISupportWorkflowChanges)
                        If (activityExecutor Is Nothing) Then
                            Throw New ApplicationException(SR.GetString("Error_WorkflowChangesNotSupported", New Object() { activity.GetType.FullName }))
                        End If
                        [Using] workflowCoreRuntime.SetCurrentActivity(activity)
                            [Using] context As ActivityExecutionContext = New ActivityExecutionContext(activity)
                                If TypeOf action Is AddedActivityAction Then
                                    Dim activity2 As Activity = activity.Activities.Item(DirectCast(action, AddedActivityAction).Index)
                                    If WorkflowChanges.IsActivityExecutable(activity2) Then
                                        activity2.OnActivityExecutionContextLoad(context.Activity.RootActivity.WorkflowCoreRuntime)
                                        context.InitializeActivity(activity2)
                                        activityExecutor.OnActivityAdded(context, activity2)
                                    End If
                                ElseIf TypeOf action Is RemovedActivityAction Then
                                    Dim action2 As RemovedActivityAction = DirectCast(action, RemovedActivityAction)
                                    If WorkflowChanges.IsActivityExecutable(action2.OriginalRemovedActivity) Then
                                        activityExecutor.OnActivityRemoved(context, action2.OriginalRemovedActivity)
                                        If (action2.OriginalRemovedActivity.ExecutionResult <> ActivityExecutionResult.Uninitialized) Then
                                            action2.OriginalRemovedActivity.Uninitialize(context.Activity.RootActivity.WorkflowCoreRuntime)
                                            action2.OriginalRemovedActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized)
                                        End If
                                        action2.OriginalRemovedActivity.OnActivityExecutionContextUnload(context.Activity.RootActivity.WorkflowCoreRuntime)
                                        action2.OriginalRemovedActivity.Dispose
                                    End If
                                End If
                            End [Using]
                            [Continue] For
                        End [Using]
                    End If
                End If
            Next
        End Sub

        Private Sub OnActivityListChanged(ByVal sender As Object, ByVal e As ActivityCollectionChangeEventArgs)
            If (Not e.RemovedItems Is Nothing) Then
                Dim activity As Activity
                For Each activity In e.RemovedItems
                    If activity.Readonly Then
                        Me.ReleaseDynamicUpdateMode(activity)
                    End If
                Next
            End If
        End Sub

        Private Sub ReleaseDynamicUpdateMode(ByVal seedActivity As Activity)
            Dim queue As New Queue([Of] Activity)
            queue.Enqueue(seedActivity)
            Do While (queue.Count > 0)
                Dim activity As Activity = queue.Dequeue
                activity.Readonly = False
                activity.DynamicUpdateMode = False
                Dim property As DependencyProperty
                For Each property In activity.MetaDependencyProperties
                    If activity.IsBindingSet([property]) Then
                        Dim binding As ActivityBind = activity.GetBinding([property])
                        If (Not binding Is Nothing) Then
                            binding.DynamicUpdateMode = False
                        End If
                    End If
                Next
                If TypeOf activity Is CompositeActivity Then
                    Dim activity2 As CompositeActivity = [TryCast](activity,CompositeActivity)
                    RemoveHandler activity2.Activities.ListChanged, New EventHandler([Of] ActivityCollectionChangeEventArgs)(AddressOf Me.OnActivityListChanged)
                    Dim activity3 As Activity
                    For Each activity3 In DirectCast(activity, CompositeActivity).Activities
                        queue.Enqueue(activity3)
                    Next
                End If
            Loop
        End Sub

        Private Sub Save()
            Dim errors As ValidationErrorCollection = Me.Validate
            If errors.HasErrors Then
                Throw New WorkflowValidationFailedException(SR.GetString("Error_CompilerValidationFailed"), errors)
            End If
            Dim originalDefinition As Object = Me.originalRootActivity.GetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp)
            Dim changedDefinition As Object = Me.clonedRootActivity.GetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp)
            If (Not originalDefinition Is Nothing) Then
                Me.modelChangeActions.AddRange(DirectCast(originalDefinition, IWorkflowChangeDiff).Diff(originalDefinition, changedDefinition))
            ElseIf (Not changedDefinition Is Nothing) Then
                Me.modelChangeActions.AddRange(DirectCast(changedDefinition, IWorkflowChangeDiff).Diff(originalDefinition, changedDefinition))
            End If
            Me.modelChangeActions.AddRange(WorkflowChanges.DiffTrees([TryCast](Me.originalRootActivity,CompositeActivity), [TryCast](Me.clonedRootActivity,CompositeActivity)))
            Me.ReleaseDynamicUpdateMode(Me.clonedRootActivity)
            Dim list As ArrayList = DirectCast(Me.clonedRootActivity.GetValue(WorkflowChanges.WorkflowChangeActionsProperty), ArrayList)
            If (list Is Nothing) Then
                list = New ArrayList
                Me.clonedRootActivity.SetValue(WorkflowChanges.WorkflowChangeActionsProperty, list)
            End If
            list.AddRange(Me.modelChangeActions)
            Me.clonedRootActivity.SetValue(WorkflowChanges.WorkflowChangeVersionProperty, Guid.NewGuid)
            Me.saved = True
            DirectCast(Me.clonedRootActivity, IDependencyObjectAccessor).InitializeDefinitionForRuntime(Nothing)
        End Sub

        Public Shared Sub SetCondition(ByVal dependencyObject As Object, ByVal value As Object)
            If (dependencyObject Is Nothing) Then
                Throw New ArgumentNullException("dependencyObject")
            End If
            If Not TypeOf dependencyObject Is DependencyObject Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(DependencyObject).FullName }), "dependencyObject")
            End If
            [TryCast](dependencyObject,DependencyObject).SetValue(WorkflowChanges.ConditionProperty, value)
        End Sub

        Public Function Validate() As ValidationErrorCollection
            Dim serviceInstance As TypeProvider = WorkflowChanges.CreateTypeProvider(Me.originalRootActivity)
            Dim service As New WorkflowCompilerOptionsService(String.Empty)
            Dim serviceProvider As New ServiceContainer
            serviceProvider.AddService(GetType(ITypeProvider), serviceInstance)
            serviceProvider.AddService(GetType(IWorkflowCompilerOptionsService), service)
            Dim manager As New ValidationManager(serviceProvider)
            Return XomlCompilerHelper.MorphIntoFriendlyValidationErrors(ValidationHelpers.ValidateObject(manager, Me.clonedRootActivity))
        End Function

        Private Sub VerifyWorkflowCanBeChanged(ByVal workflowCoreRuntime As IWorkflowCoreRuntime)
            Dim condition As ActivityCondition = [TryCast](workflowCoreRuntime.RootActivity.GetValue(WorkflowChanges.ConditionProperty),ActivityCondition)
            If (Not condition Is Nothing) Then
                [Using] workflowCoreRuntime.SetCurrentActivity(workflowCoreRuntime.RootActivity)
                    If Not condition.Evaluate(workflowCoreRuntime.RootActivity, workflowCoreRuntime) Then
                        Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_DynamicUpdateEvaluation", New Object() { workflowCoreRuntime.InstanceID.ToString }))
                    End If
                End [Using]
            End If
        End Sub


        ' Properties
        Public ReadOnly Property TransientWorkflow As CompositeActivity
            Get
                Return [TryCast](Me.clonedRootActivity,CompositeActivity)
            End Get
        End Property


        ' Fields
        Private clonedRootActivity As Activity
        Public Shared ReadOnly ConditionProperty As DependencyProperty = DependencyProperty.RegisterAttached("Condition", GetType(ActivityCondition), GetType(WorkflowChanges), New PropertyMetadata(DependencyPropertyOptions.Metadata))
        Private modelChangeActions As List([Of] WorkflowChangeAction) = New List([Of] WorkflowChangeAction)
        Private originalRootActivity As Activity
        Private saved As Boolean
        Friend Shared WorkflowChangeActionsProperty As DependencyProperty = DependencyProperty.RegisterAttached("WorkflowChangeActions", GetType(IList), GetType(WorkflowChanges), New PropertyMetadata(DependencyPropertyOptions.NonSerialized))
        Friend Shared WorkflowChangeVersionProperty As DependencyProperty = DependencyProperty.RegisterAttached("WorkflowChangeVersion", GetType(Guid), GetType(WorkflowChanges), New PropertyMetadata(Guid.Empty, DependencyPropertyOptions.NonSerialized))
    End Class
End Namespace

